<template>
  <div class="page-box">
    <Card>
      <el-table
        :data="data"
        height="calc(100vh - 195px)"
        border
        class="margin-top-5"
        style="width: 100%"
        size="mini"
        @row-dblclick="rowDblclick"
        highlight-current-row
        :header-cell-style="headerCellStyle"
        oncontextmenu="return false;"
        ref="multipleTable"
        sortable="custom"
        empty-text="暂无数据"
        v-loading="dataLoading">
        <el-table-column
          type="index"
          align="center"
          label="序号"
          width="55">
        </el-table-column>
        <el-table-column
          v-for="(item, key) in workColumns" :key="key"
          :prop="item.key"
          :label="item.title"
          :width="item.width"
          align="center"
          :formatter="item.formatter"
          :sortable="item.sortable"
          :show-overflow-tooltip="true"
          :fixed="item.key=='userName'"
        >
          <template slot-scope="scope">
            <template v-if="item.type === 'tasktp'">
              <div :class="[scope.row.tasktp === 'out' ? 'tips-out' : 'tips-in']">{{ handlePlanType(scope.row.tasktp) }}</div>
            </template>
            <template v-else-if="item.type !== 'template'">
              {{ $table.tableRowFormat(scope.row, item) }}
            </template>
          </template>
        </el-table-column>
      </el-table>
    </Card>
    <work-detail-modal ref="workDetail" />
  </div>
</template>

<script>

import {workColumns} from "@/view/wms/js/column";
import {useCustomer, useHeaderCellStyle, useHttp, useWorkType} from "@/view/wms/js";
import WorkDetailModal from "@/view/wms/comp/WorkDetailModal.vue";

export default {
  name: "RealTimeWork",
  components: {WorkDetailModal},
  computed: {
    headerCellStyle() {
      return useHeaderCellStyle();
    }
  },
  data() {
    return {
      dataLoading: false,
      show: false,
      workColumns,
      data: []
    }
  },
  methods: {
    handlePlanType(type) {
      return useWorkType(type);
    },
    rowDblclick(row) {
      this.show = true;
      this.$refs.workDetail.open(row);
    },
    init() {
      this.dataLoading = true;
      useHttp('/WisdomWMSWebAPI/ParkTask/FindInWarehouseTask', {
        customer_code: useCustomer(this)
      }).then(res => {
        const {message, data} = res.data;
        if (message === 'success') {
          this.data = data;
        } else {
          this.$message.warning('接口请求失败！');
        }
      }).finally(() => {
        this.dataLoading = false;
      });
    }
  },
  created() {
    this.$nextTick(() => {
      this.init();
    });
  }
}
</script>

<style scoped lang="less">
.common {
  width: 20px;
  height: 20px;
  position: absolute;
  border-radius: 50%;
  left: 10px;
  color: #fff;
  text-align: center;
  line-height: 20px;
}
.tips-out {
  position: relative;
  &:before {
    content: '出';
    background-color: #0ee7fc;
    .common
  }
}
.tips-in {
  position: relative;
  &:before {
    content: '入';
    background-color: #02fd8c;
    .common
  }
}
</style>
